#include <stdio.h>
#include <stdlib.h>
//输入学生个数
//输入学生性别（0女，1男），姓名
//输入顺序代表名次，将最靠前与最靠后的异性同学配对
typedef struct stu
{
    char name[8];
    int gender;
    int pair;
}stu;

int main()
{
    int N = 0, i, j;
    scanf("%d", &N);
    stu* student = (stu*)malloc(sizeof(stu) * N);
    for(i = 0;i < N;i++)
    {
        scanf("%d %s", &student[i].gender, &student[i].name);
        student[i].pair = 0;
    }
    for(i = 0;i <= N/2;i++)
    {
        for(j = N-1;j > i;j--)
        {
            if(student[j].pair == 0&&(student[i].gender != student[j].gender))
            {
                student[j].pair = 1;
                student[i].pair = j;
                break;
            }
        }
    }
    for(i = 0;i < N/2;i++)
    {
        j = student[i].pair;
        printf("%s %s\n", student[i].name, student[j].name);
    }
    return 0;
}